package com.maikec.utils.scheduled;
/**
 * 邢帅教育
 * <p>
 * 本源代码由数据中心及其作者共同所有，未经版权持有者的事先书面授权，
 * 不得使用、复制、修改、合并、发布、分发和/或销售本源代码的副本。
 *
 * @copyright Copyright (c) 2018. [图片]xsteach.com all rights reserved.
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @description
 * @author maikec
 * @date 2018/7/9
 */
@Component
public class ScheduledTasks {
    @Autowired
    private TaskExecutorExample taskExecutorExample;
    private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        log.info("The time is now {}", dateFormat.format(new Date()));
    }

    @Scheduled(cron="*/5 * * * * *")
    @Async
    public void doSomething() {
        // something that should execute on weekdays only
        taskExecutorExample.printMessages();
    }

    @Scheduled(cron="*/5 * * * * *")
    @Async
    public void doSomething2() {
        // something that should execute on weekdays only
        taskExecutorExample.printMessages();
    }
}
